import "package:sports_new/entity/match/detail/lq_lineup_entity.dart";
import "package:sports_new/entity/match/detail/lq_match_data_compare_entity.dart";
import "package:sports_new/entity/match/detail/lq_match_data_entity.dart";
import "package:sports_new/entity/match/hot_league_list_entity.dart";
import "package:sports_new/entity/match/lq_list_entity.dart";
import "package:sports_new/entity/match/zq_odds_entity.dart";
import "package:sports_new/entity/team/lq_team_count_entity.dart";
import "package:sports_new/entity/team/lq_team_data_year_entity.dart";
import "package:sports_new/entity/team/lq_team_detail_entity.dart";
import "package:sports_new/entity/team/lq_team_player_entity.dart";
import "package:sports_new/entity/team/lq_team_schedule_entity.dart";
import "package:sports_new/server/http/dio_utils.dart";
import "package:sports_new/utils/user.dart";

import "../../entity/match/detail/lq_detail_head_entity.dart";
import "../../entity/match/zq_match_intelligence_entity.dart";
import "../api_dir.dart";

class BasketballApi {
  ///篮球热门、一级联赛列表
  static Future<HotLeagueListEntity?> getHotLqLeagueList() async {
    try {
      final result =
      await DioUtils.post(
          "/${ApiDir.basketball}/app-basketball-match-do/leagues");
      if (result.statusCode == 200 && result.data["c"] == 200) {
        final data = HotLeagueListEntity.fromJson(result.data["d"]);
        return data;
      }
    }catch(e){

    }
    return null;
  }

  ///获取全部比赛
  static Future<List<LqListEntity>?> getLqAllList() async {
    final result = await DioUtils.post("/${ApiDir.basketball}/app-bb-do/matchAll");
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<LqListEntity> data = result.data["d"]
          .map<LqListEntity>((e) => LqListEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///获取进行中比赛
  static Future<List<LqListEntity>?> getLqBeginList() async {
    final result = await DioUtils.post("/${ApiDir.basketball}/app-bb-do/matchIng");
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<LqListEntity> data = result.data["d"]
          .map<LqListEntity>((e) => LqListEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///获取比赛赛果
  static Future<List<LqListEntity>?> getLqResultList(String time) async {
    final params = {"id": time};
    final result =
        await DioUtils.post("/${ApiDir.basketball}/app-bb-do/matchResult", params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<LqListEntity> data = result.data["d"]
          .map<LqListEntity>((e) => LqListEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///获取比赛赛程
  static Future<List<LqListEntity>?> getLqNotBeginList(String time) async {
    final params = {"id": time};
    final result = await DioUtils.post("/${ApiDir.basketball}/app-bb-do/matchSchedule",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<LqListEntity> data = result.data["d"]
          .map<LqListEntity>((e) => LqListEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///获取热门比赛
  static Future<List<LqListEntity>?> getLqHotList(String id, {String? teamId}) async {
    final result = await DioUtils.post(
      "/${ApiDir.basketball}/app-bb-do/matchCustom",
      params: {"id": id,"teamId":teamId}
    );
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<LqListEntity> data = result.data["d"]
          .map<LqListEntity>((e) => LqListEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///获取用户关注
  static Future<List<LqListEntity>?> getLqFocusList() async {
    final result = await DioUtils.post("/${ApiDir.basketball}/app-bb-do/matchFocus",
        params: {"id": User.auth?.userId ?? ""});
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<LqListEntity> data = result.data["d"]
          .map<LqListEntity>((e) => LqListEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  //篮球比赛对比、场均
  static Future<LqMatchDataCompareEntity?> getLqTeamCompare(int id) async {
    final params = {
      "qxbMatchId": id,
    };
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-match-do/appTeamSimple",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      LqMatchDataCompareEntity data =
          LqMatchDataCompareEntity.fromJson(result.data["d"]);
      return data;
    }
    return null;
  }

  ///篮球比赛对阵数据
  static Future<LqMatchDataEntity?> getLqTeamMatchData(int id) async {
    final params = {
      "qxbMatchId": id,
    };
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-match-do/teamMatchData",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      LqMatchDataEntity data = LqMatchDataEntity.fromJson(result.data["d"]);
      return data;
    }
    return null;
  }

  ///篮球详情情报
  static Future<ZqMatchIntelligenceEntity?> getLqInfo(int id) async {
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-match-do/teamRemark",
        params: {"matchId": id});
    if (result.statusCode == 200 && result.data["c"] == 200) {
      ZqMatchIntelligenceEntity data =
          ZqMatchIntelligenceEntity.fromJson(result.data["d"]);
      return data;
    }
    return null;
  }

  static lqMatchDetail(int id) =>
      DioUtils.post("/${ApiDir.basketball}/app-basketball-match-do/detail",
          params: {"matchQxbId": id});

  static Future<LqDetailHeadInfoEntity?> lqMatchDetailHead(int id) async {
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-match-do/head",
        params: {"matchQxbId": id});
    if (result.statusCode == 200 && result.data["c"] == 200) {
      LqDetailHeadInfoEntity data =
      LqDetailHeadInfoEntity.fromJson(result.data["d"]);
      return data;
    }
    return null;
  }

  ///篮球详情阵容关键数据
  static Future<LqLineupKeyDataEntity?> getLqLineupKeyData(int id) async {
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-match-do/keyData",
        params: {"matchId": id});
    if (result.statusCode == 200 && result.data["c"] == 200) {
      LqLineupKeyDataEntity data =
          LqLineupKeyDataEntity.fromJson(result.data["d"]);
      return data;
    }
    return null;
  }

  ///篮球详情阵容列表
  static Future<List<BbLineupDataEntity>?> getLqLineupData(
      int id, int teamType) async {
    final params = {
      "matchId": id,
      "teamType": teamType,
    };
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-match-do/player/technic",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<BbLineupDataEntity> data = result.data["d"]
          .map<BbLineupDataEntity>((e) => BbLineupDataEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///篮球详情阵容伤病列表
  static Future<BbLineupSuspendDataEntity?> getLqLineupSuspendData(
      int id) async {
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-match-do/player/injury",
        params: {"matchId": id});
    if (result.statusCode == 200 && result.data["c"] == 200) {
      BbLineupSuspendDataEntity data =
          BbLineupSuspendDataEntity.fromJson(result.data["d"]);
      return data;
    }
    return null;
  }

  ///篮球比赛详情指数
  static Future<List<ZqOddsEntity>?> getLqMatchOdds(
      int playType, int id) async {
    final params = {"playType": playType, "qxbMatchId": id};
    final result =
        await DioUtils.post("/${ApiDir.basketball}/app-odds-do/exponent", params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<ZqOddsEntity> data = result.data["d"]
          .map<ZqOddsEntity>((e) => ZqOddsEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///篮球详情指数详情
  static Future<List<SoccerOddsDetailEntity>?> getLqMatchOddsDetail(
      int id, int companyId, int playType, String line) async {
    final params = {
      "companyId": companyId,
      "playType": playType,
      "qxbMatchId": id,
      "line": line
    };
    final result = await DioUtils.post("/${ApiDir.basketball}/app-odds-do/exponentInfo",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<SoccerOddsDetailEntity> data = result.data["d"]
          .map<SoccerOddsDetailEntity>(
              (e) => SoccerOddsDetailEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///篮球详情指数详情公司列表
  static Future<List<SoccerOddsCompanyEntity>?> getLqMatchOddsCompany(
      int id, int playType) async {
    final params = {"playType": playType, "qxbMatchId": id};
    final result = await DioUtils.post("/${ApiDir.basketball}/app-odds-do/companyArray",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<SoccerOddsCompanyEntity> data = result.data["d"]
          .map<SoccerOddsCompanyEntity>(
              (e) => SoccerOddsCompanyEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///篮球球队简介
  static Future<LqTeamDetailEntity?> getlqTeamDetail(int id) async {
    final params = {"id": id};
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-team-channel-do/view",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      LqTeamDetailEntity data = LqTeamDetailEntity.fromJson(result.data["d"]);
      return data;
    }
    return null;
  }

  ///篮球球队数据年份
  static Future<List<LqTeamDataYearEntity>?> getLqTeamDataYear(int id) async {
    final params = {
      "id": id,
    };
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-team-channel-do/statisticsYear",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<LqTeamDataYearEntity> data = result.data["d"]
          .map<LqTeamDataYearEntity>((e) => LqTeamDataYearEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///篮球球队阵容年份
  static Future<List<LqTeamDataYearEntity>?> getLqTeamLineupYear(int id) async {
    final params = {
      "id": id,
    };
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-team-channel-do/squadYear",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<LqTeamDataYearEntity> data = result.data["d"]
          .map<LqTeamDataYearEntity>((e) => LqTeamDataYearEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///篮球球队阵容
  static Future<List<LqTeamPlayerEntity>?> getLqTeamLineup(
      int qxbTeamId, int? seasonId, int? leagueId, int? scopeId) async {
    final params = {
      "qxbTeamId": qxbTeamId,
      "seasonId": seasonId,
      "leagueId": leagueId,
      "scopeId": scopeId,
    };
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-team-channel-do/squad",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      List<LqTeamPlayerEntity> data = result.data["d"]
          .map<LqTeamPlayerEntity>((e) => LqTeamPlayerEntity.fromJson(e))
          .toList();
      return data;
    }
    return null;
  }

  ///篮球球队统计
  static Future<LqTeamCountEntity?> getLqTeamStatistics(int qxbTeamId,
      int seasonId, int? leagueId, int? scopeId, int? stageId) async {
    final params = {
      "qxbTeamId": qxbTeamId,
      "seasonId": seasonId,
      "leagueId": leagueId,
      "scopeId": scopeId,
      "stageId": stageId
    };
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-team-channel-do/statistics",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      LqTeamCountEntity data = LqTeamCountEntity.fromJson(result.data["d"]);
      return data;
    }
    return null;
  }

  ///篮球球队赛程年份
  static Future<List<LqTeamScheduleYearEntity>> getLqTeamScheduleYear(
      int id) async {
    try {
      final result = await DioUtils.post(
          "/${ApiDir
              .basketball}/app-basketball-team-channel-do/matchScheduleYear",
          params: {"id": id});
      if (result.statusCode == 200 && result.data["c"] == 200) {
        List<LqTeamScheduleYearEntity> data = result.data["d"]
            .map<LqTeamScheduleYearEntity>(
                (e) => LqTeamScheduleYearEntity.fromJson(e))
            .toList();
        return data;
      }
    }catch(e){
      return [];
    }
    return [];
  }

  ///篮球球队赛程
  static Future<LqTeamScheduleEntity?> getLqTeamSchedule(int id, String year,
      {int? kind, int? leagueId}) async {
    final params = {
      "qxbTeamId": id,
      "matchYear": year,
      "kind": kind,
      "leagueId": leagueId
    };
    final result = await DioUtils.post(
        "/${ApiDir.basketball}/app-basketball-team-channel-do/matchSchedule",
        params: params);
    if (result.statusCode == 200 && result.data["c"] == 200) {
      LqTeamScheduleEntity data =
          LqTeamScheduleEntity.fromJson(result.data["d"]);
      return data;
    }
    return null;
  }
}
